package com.mes.controller.manu;

import com.mes.service.manu.CooperativeVehicleService;
import com.yy.base.common.action.BaseCtrl;
import com.yy.base.page.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("Vehicle")
public class CooperativeVehicleController extends BaseCtrl {
	@Autowired
	private CooperativeVehicleService cooperativeVehicleService;

	//根据传过来的RFID带出明细信息
	@ResponseBody
	@RequestMapping(value="getVehicleLists", method=RequestMethod.POST)
	public Message getVehicleLists(HttpServletRequest request) {
		Message msg = new Message();

		try{

		String code = request.getParameter("PhotoCode").toString();   //矢量图编码

		msg.setData("PhotoListsRight",cooperativeVehicleService.getPhotoListsRight(code));
		msg.setData("PhotoListsLeft",cooperativeVehicleService.getPhotoListsLeft(code));

		List<Map<String, Object>> hicleList = cooperativeVehicleService.getPhotoListsLeft(code);

		String exeID = hicleList.get(0).get("EXEIDS").toString();

		String stauts = hicleList.get(0).get("STATUSS").toString();

		String zystauts = hicleList.get(0).get("ZYSTATUS").toString();

		String ending = "";

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		Date time  =sdf.parse(sdf.format(new Date())); //获取当前系统时间
		if(stauts.equals("FINISHED")){
			if(zystauts.equals("CREATE")){
				/*List<Map<String, Object>> ListProduct = cooperativeVehicleService.getProductJbLists(code); //传过来的是工单RFID号

				if(ListProduct.size() == 0 || ListProduct.size() == 0){
					msg.setData("result","false");
					return msg;
				}

				for(int i = 0; i< ListProduct.size(); i++){
					String WLID = ListProduct.get(i).get("WLID").toString();  //物料ID
					String RFIDCODE = ListProduct.get(i).get("RFIDCODE").toString();  //对应夹板RFID


					List<Map<String, Object>> mescode = cooperativeVehicleService.selectWarehouseCode(WLID);

					String ckCode = mescode.get(0).get("CKCODE").toString();  //MES参数编码（仓库编码）

					//调用接口往中间表插数据
					WCSUtils.outStorck(ckCode, RFIDCODE,  1, code);
				}*/

				/*if(){

				}*/
				ending = "START";
				cooperativeVehicleService.updateExeBeginStatus(exeID,ending);
			}else if(zystauts.equals("START")){
				ending = "FINISHED";
				cooperativeVehicleService.updateExeEndStatus(exeID,ending);
			}
		}

		}catch (Exception e){
			msg.setData("results","false");
			e.printStackTrace();
		}
		return msg;
	}

}